<tc_include file="Public:head"/>
<body ontouchstart style="background: #f1f1f1;">
<div class="container" id="container">
    <div class="page">
        <div class="page__bd" style="height: 100%; overflow: hidden;">
            <div class="weui-tab">
                <div class="weui-tab__panel">
                    <div class="reg-box">
                        <!--注册-->
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell">
                                <div class="weui-cell__hd">
                                    <label class="weui-label">原密码</label>
                                </div>
                                <div class="weui-cell__bd">
                                    <input id="old_password" class="weui-input" type="number" placeholder="原密码">
                                </div>
                            </div>
                            <div class="weui-cell">
                                <div class="weui-cell__hd">
                                    <label class="weui-label">新密码</label>
                                </div>
                                <div class="weui-cell__bd">
                                    <input id="new_password" class="weui-input" type="number" placeholder="请输入新密码">
                                </div>
                            </div>
                        </div>
                        <div class="weui-btn-area">
                            <a class="weui-btn weui-btn_default" href="javascript:"
                               id="btn_submit">确认<br/><span>submit</span></a>
                        </div>

                        <!--注册 end-->
                    </div>
                </div>

                <tc_include file="Public:menu"/>
            </div>
        </div>
    </div>
</div>
<div id="dialogs">
    <!--BEGIN errDialog-->
    <div class="js_dialog" id="errDialog" style="display: none;">
        <div class="weui-mask"></div>
        <div class="weui-dialog notice-dialog">
            <div class="weui-dialog__btn">&times;</div>
            <div class="icon-box">
                <i class="icon iconfont icon-notice"></i>
            </div>
            <div class="weui-dialog__bd">
                <div class="weui-dialog__title">修改成功！</div>
                <p>欢迎加入夏都小镇，<font>即将跳转会员页面！</font></p>
            </div>
        </div>
    </div>
    <!--END errDialog-->

</div>
<tc_include file="Public:footer"/>
<script>


    function show_dialog(code, title, content) {
        if (code == 200) {
            $(".weui-dialog__bd .weui-dialog__title").html("修改成功！");
            $(".weui-dialog__bd p").html('欢迎加入夏都小镇，<font>即将跳转会员页面！</font>');
        }
        else {
            $(".weui-dialog__bd .weui-dialog__title").html(title);
            $(".weui-dialog__bd p").html(content);
        }
        $('#errDialog').fadeIn(0);
    }


    $("#btn_submit").click(function () {
        var old_password = $("#old_password").val();
        var new_password = $("#new_password").val();

        var isPassword = /^[0-9a-zA-Z_]{6,15}$/;

        if (!isPassword.exec(old_password)) {
            show_dialog(0, '修改失败！', '原密码不正确，请重新输入');
            return false;
        }

        if (!isPassword.exec(new_password)) {
            show_dialog(0, '修改失败！', '新密码格式不正确，请重新输入');
            return false;
        }

        $.post('{:U("member/doModifypwd")}', {old_password: old_password, new_password: new_password}, function (data) {
            if (data.code == 200) {
                show_dialog(200);
                setTimeout(function () {
                    location.href = '{:U("member/MemberDetail")}';
                }, 1000);
            }
            else {
                show_dialog(data.code, '修改失败', data.message);
            }
        });
    });

    //关闭dialogs
    $('#dialogs').on('click', '.weui-dialog__btn', function () {
        $(this).parents('.js_dialog').fadeOut(0);
    });
</script>
